home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Risc World 3
/
Risc World 3.iso
/
SOFTWARE
/
ISSUE6
/
PD
/
PDF
/
pdf
/
c++
/
DocViewToolbar
< prev
next >
Wrap
Text File
|
2003-02-24
|
9KB
|
263 lines
//--------------------------------------------------------------------------
//
// Copyright (c) 2002, Colin Granville
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or
// without modification, are permitted provided that the following
// conditions are met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials
// provided with the distribution.
//
// * The name Colin Granville may not be used to endorse or promote
// products derived from this software without specific prior
// written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
// OF THE POSSIBILITY OF SUCH DAMAGE.
//
//--------------------------------------------------------------------------
#include "DocViewToolbar.h"
#include "DocView.h"
#include "guilib:gfx.h"
#include "UserEvents.h"
#include "Document.h"
#include "outline.h"
DocViewToolbar::DocViewToolbar(DocView& docView,GuiWindow& ancestor)
: GuiWindow("toolbar"),
view(docView),
page(*this,0xe),
lastPage(*this,8),
pageSlider(*this,0xf),
outline(*this,0x89),
logicalPageOffset(0),
currentPage(0),
pageCount(1),
oldWidth(-1),
history(docView,*this,ancestor),
bookmarks(docView,*this,ancestor),
showOutlineTarget(&ancestor,User_ShowOutline,this,DocViewToolbar::showOutline),
adjusterClickedTarget(&ancestor,User_AdjusterClicked,this,DocViewToolbar::adjusterClicked),
readPageTarget(&ancestor,User_ReadPage,this,DocViewToolbar::readPage),
sliderValueChangedTarget(&ancestor,GuiSlider::ValueChanged::Event,
this,DocViewToolbar::sliderValueChanged),
nextPartPageTarget(&ancestor,User_NextPartPage,this,DocViewToolbar::nextPage),
nextPageTarget(&ancestor,User_NextPage,this,DocViewToolbar::nextPage),
fastNextPageTarget(&ancestor,User_FastNextPage,this,DocViewToolbar::nextPage),
previousPartPageTarget(&ancestor,User_PreviousPartPage,this,DocViewToolbar::previousPage),
previousPageTarget(&ancestor,User_PreviousPage,this,DocViewToolbar::previousPage),
fastPreviousPageTarget(&ancestor,User_FastPreviousPage,this,DocViewToolbar::previousPage),
logicalPageNumberATBSTarget(&ancestor,User_LogicalPageNumberATBS,
this,DocViewToolbar::logicalPageNumberATBS),
logicalPageNumberSetTarget(&ancestor,User_LogicalPageNumberSet,
this,DocViewToolbar::logicalPageNumberSet)
{
}
//*************************************************************************
DocViewToolbar::~DocViewToolbar()
{
Outline* o=view.getDocument().getOutline();
if (o) o->close(view);
}
//*************************************************************************
void DocViewToolbar::goBack()
{
const DocPage* page=history.back();
if (page) setPage(page->page,0);
}
//*************************************************************************
void DocViewToolbar::openWindow(GuiWindow& parent,GuiGetWindowStateBlock& parent_state)
{
GuiGetWindowStateBlock b;
getState(b);
b.behind=parent_state.behind;
parent_state.behind=b.windowHandle;
b.visibleArea.xmin=parent_state.visibleArea.xmin;
b.visibleArea.xmax=b.visibleArea.xmin+parent_state.visibleArea.getWidth();
int ht=b.visibleArea.getHeight();
b.visibleArea.ymax=parent_state.visibleArea.ymax;
b.visibleArea.ymin=b.visibleArea.ymax-ht;
show(b,&parent);
int new_width=parent_state.visibleArea.getWidth();
if (new_width!=oldWidth)
{
oldWidth=new_width;
GuiBBox box;
pageSlider.getBBox(box);
box.xmax=new_width-6;
pageSlider.move(box);
}
return;
}
//*************************************************************************
void DocViewToolbar::setFirstPage(int page_ ,int logicalPO, int page_count,bool add_to_history)
{
if (page_count<=0) page_count=1;
if (page_ >= page_count) page_=page_count;
if (page_ <=0) page_=1;
page.setFocus();
logicalPageOffset=logicalPO;
currentPage=page_;
pageCount=page_count;
page.setNumber(currentPage+logicalPageOffset);
lastPage.setNumber(pageCount);
// crashes if upper==lower
pageSlider.setBounds( GuiSlider::SetUpper | GuiSlider::SetLower | GuiSlider::SetStepSize,
1,(pageCount==1?2:pageCount),1);
pageSlider.setValue(currentPage);
Outline* o=view.getDocument().getOutline();
outline.fade(!(o && o->isOk()));
if (add_to_history) history.add(currentPage);
}
//*************************************************************************
void DocViewToolbar::setPage(int new_page, bool set_history)
{
if (new_page>pageCount) new_page=pageCount;
if (new_page<=0) new_page=1;
if (new_page==currentPage) return;
currentPage=new_page;
if (set_history) history.add(currentPage);
pageSlider.setValue(currentPage);
page.setNumber(currentPage+logicalPageOffset);
view.showPage();
}
//*************************************************************************
Claim DocViewToolbar::showOutline(GuiToolboxEvent&,const GuiIdBlock&)
{
Outline* o=view.getDocument().getOutline();
if (o) o->open(view);
outline.fade(!(o && o->isOk()));
return CLAIM;
}
//*************************************************************************
Claim DocViewToolbar::adjusterClicked(GuiToolboxEvent& ev,const GuiIdBlock& id_block)
{
if (id_block.self.component==0x87)
{
ev.eventCode=User_PreviousPartPage;
if (gfx::inkey(-1)) ev.eventCode=User_PreviousPage; //shift
if (gfx::inkey(-2)) ev.eventCode=User_FastPreviousPage; //ctrl
return previousPage(ev,id_block);
}
ev.eventCode=User_NextPartPage;
if (gfx::inkey(-1)) ev.eventCode=User_NextPage; //shift
if (gfx::inkey(-2)) ev.eventCode=User_FastNextPage; //ctrl
return nextPage(ev,id_block);
};
//*************************************************************************
Claim DocViewToolbar::readPage(GuiToolboxEvent&,const GuiIdBlock&)
{
setPage(page.getNumber()-logicalPageOffset);
view.scroll(DocView::SCROLL_TOP);
return CLAIM;
};
//*************************************************************************
Claim DocViewToolbar::sliderValueChanged(GuiToolboxEvent& ev,const GuiIdBlock&)
{
GuiSlider::ValueChanged& s= (GuiSlider::ValueChanged&)ev;
if (s.flags == GuiSlider::ValueChanged::DragStart) history.addPending();
if (s.newValue<=pageCount && currentPage!=s.newValue)
{
currentPage=s.newValue;
page.setNumber(currentPage+logicalPageOffset);
view.showPage();
history.addPending(currentPage);
}
return CLAIM;
}
//*************************************************************************
Claim DocViewToolbar::nextPage(GuiToolboxEvent& ev,const GuiIdBlock&)
{
if (ev.eventCode==User_NextPartPage && view.scroll(DocView::SCROLL_DOWN)) return CLAIM;
int page=currentPage;
setPage(currentPage+(ev.eventCode==User_FastNextPage?10:1));
if (page!=currentPage) view.scroll(DocView::SCROLL_TOP);
return CLAIM;
}
//*************************************************************************
Claim DocViewToolbar::previousPage(GuiToolboxEvent& ev,const GuiIdBlock&)
{
if (ev.eventCode==User_PreviousPartPage && view.scroll(DocView::SCROLL_UP)) return CLAIM;
int page=currentPage;
setPage(currentPage-(ev.eventCode==User_FastPreviousPage?10:1));
if (page!=currentPage)
view.scroll(ev.eventCode==User_PreviousPartPage ? DocView::SCROLL_BOTTOM : DocView::SCROLL_TOP);
return CLAIM;
}
//*************************************************************************
Claim DocViewToolbar::logicalPageNumberATBS(GuiToolboxEvent&,const GuiIdBlock& idBlock)
{
GuiWindow win(idBlock.self.id);
NumberField(win,0).setNumber(currentPage+logicalPageOffset);
return CLAIM;
}
//*************************************************************************
Claim DocViewToolbar::logicalPageNumberSet(GuiToolboxEvent&,const GuiIdBlock& idBlock)
{
GuiWindow win(idBlock.self.id);
logicalPageOffset = NumberField(win,0).getNumber()-currentPage;
page.setNumber(currentPage+logicalPageOffset);
return CLAIM;
}